home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-10-23 | 6.7 KB | 357 lines | [TEXT/CWIE] |
- // TabPanel.cp
-
- #include <Types.h>
- #include <Quickdraw.h>
- #include <Controls.h>
- #include <Dialogs.h>
- #include <Events.h>
- #include <Lists.h>
- #include <Menus.h>
- #include <Resources.h>
- #include <Sound.h>
- #include <TextEdit.h>
- #include <ToolUtils.h>
- #include <Appearance.h>
-
- #include "Globals.h"
- #include "ResourceDefs.h"
- #include "DoScrap.h"
- #include "Miscellany.h"
- #include "Scrolling.h"
- #include "ControlUtils.h"
- #include "DDocData.h"
- #include "LayerGroupsEngine.h"
- #include "LayerGroupsDoc.h"
-
- #include "TabPanel.h"
-
-
- //----------
- void TabPanel::Create (
- AMDoc* inDoc,
- DDocData* inData)
- {
- TabPanel* winObj = new TabPanel;
-
- if (winObj != nil) {
- winObj->Open (inDoc);
- winObj->ConnectToData (inData);
- }
- }
-
- //----------
- TabPanel::TabPanel ()
- {
- mData = nil;
- }
-
- //----------
- TabPanel::~TabPanel ()
- {
- }
-
- //----------
- LayerGroupsEngine* TabPanel::GetEngine ()
- {
- return (LayerGroupsEngine*) mDoc->mEngine;
- }
-
- //----------
- void TabPanel::Open (
- AMDoc* inDoc)
- {
- WindowPtr window;
- Handle wftb;
-
- mDoc = inDoc;
-
- window = GetNewCWindow (WIND_TabPanel, nil, (WindowPtr) -1L);
- if (mDoc->mEngine->GetFilename () [0] != 0) {
- SetWTitle (window, mDoc->mEngine->GetFilename ());
- }
- mWindow = window;
- ((LayerGroupsDoc*)mDoc)->mTabPanelPtr = window;
-
- SetWindowKind (window, 'AM');
- SetWRefCon (window, (long) this);
- SetPort (window);
- SetInfo (window);
-
- wftb = ::GetResource ('Wftb', WIND_TabPanel);
-
- CreateRootControl (window, &mRootControl);
-
- vScroll = nil;
- hScroll = nil;
-
-
- mTabsHandle = ::GetNewControl (CNTL_Tabs, window);
- SetWindowItemFont (mTabsHandle, wftb, 1);
-
-
- mFredHandle = ::GetNewControl (CNTL_Fred, window);
- EmbedControl (mFredHandle, mTabsHandle);
- SetWindowItemFont (mFredHandle, wftb, 2);
-
- mTheseWindowsShowSeveralVaLabel = GetNewControl (CNTL_TheseWindowsShowSeveralVa, window);
- EmbedControl (mTheseWindowsShowSeveralVaLabel, mFredHandle);
- SetWindowItemFont (mTheseWindowsShowSeveralVaLabel, wftb, 3);
- SetControlFromTEXT (mTheseWindowsShowSeveralVaLabel, TEXT_TheseWindowsShowSeveralVa);
-
-
- mGeorgeHandle = ::GetNewControl (CNTL_George, window);
- EmbedControl (mGeorgeHandle, mTabsHandle);
- SetWindowItemFont (mGeorgeHandle, wftb, 4);
-
- mEditTextHandle = ::GetNewControl (CNTL_EditText, window);
- EmbedControl (mEditTextHandle, mGeorgeHandle);
- SetWindowItemFont (mEditTextHandle, wftb, 5);
-
-
- mHarryHandle = ::GetNewControl (CNTL_Harry, window);
- EmbedControl (mHarryHandle, mTabsHandle);
- SetWindowItemFont (mHarryHandle, wftb, 6);
-
- mScrollBarHandle = ::GetNewControl (CNTL_ScrollBar, window);
- EmbedControl (mScrollBarHandle, mHarryHandle);
- SetWindowItemFont (mScrollBarHandle, wftb, 7);
-
- AdvanceKeyboardFocus (window);
-
- ShowWindow (window);
- }
-
- //----------
- void TabPanel::Close ()
- {
- mData->RemoveResponder (this);
-
- ((LayerGroupsDoc*)mDoc)->mTabPanelPtr = nil;
- SetInfo (nil);
- HideWindow (mWindow);
- DisposeWindow (mWindow);
-
- delete this;
- }
-
- //----------
- void TabPanel::ConnectToData (
- DDocData* inData)
- {
- mData = inData;
- mData->AddResponder (this);
-
- SetControlValue (mTabsHandle, mData->GetTabs ());
- SetLayerGroupValue (mTabsHandle, GetControlValue (mTabsHandle));
- SetClockDateTime (mEditTextHandle, mData->GetEditText ());
- SetControlValue (mScrollBarHandle, mData->GetScrollBar ());
- }
-
- //----------
- void TabPanel::DataChanged (
- long inDataID)
- {
- if (inDataID == idTabs) {
- SetControlValue (mTabsHandle, mData->GetTabs ());
- SetLayerGroupValue (mTabsHandle, mData->GetTabs ());
- }
- if (inDataID == idEditText) {
- SetClockDateTime (mEditTextHandle, mData->GetEditText ());
- }
- if (inDataID == idScrollBar) {
- SetControlValue (mScrollBarHandle, mData->GetScrollBar ());
- }
- }
-
- //----------
- void TabPanel::Control (
- ControlHandle whichControl,
- short whichPart,
- Point where)
- {
- Rect bounds;
- short newValue;
-
- ExitCurField ();
-
- if (whichControl == mTabsHandle) {
- if (TrackClick (mTabsHandle, where) != 0) {
- mData->SetTabs (GetControlValue (mTabsHandle));
- }
- }
- if (whichControl == mEditTextHandle) {
- HandleEditClick (mEditTextHandle, where);
- mData->SetEditText (GetClockDateTime (mEditTextHandle));
- }
- if (whichControl == mScrollBarHandle) {
- HandleControlClick (mScrollBarHandle, where, curEvent.modifiers, nil);
- mData->SetScrollBar (GetControlValue (mScrollBarHandle));
- }
- }
-
- //----------
- void TabPanel::MouseIn (
- Point where,
- short modifiers)
- {
- Rect bounds;
-
- }
-
- //----------
- void TabPanel::ExitCurField ()
- {
- ControlHandle focus;
-
- GetKeyboardFocus (mWindow, &focus);
-
- if (focus == nil) {
- // nothing to exit
-
- } else if (focus == mEditTextHandle) {
- mData->SetEditText (GetClockDateTime (mEditTextHandle));
- }
- }
-
- //----------
- void TabPanel::TypeIn (
- char ch)
- {
- ControlHandle focus;
- SInt16 keyCode;
-
- GetKeyboardFocus (mWindow, &focus);
-
- if ((ch == charEnter)
- || (ch == charReturn)) {
- ExitCurField ();
- } else if (ch == charEsc) {
- } else if (ch == charTab) {
- DoTab ((curEvent.modifiers & optionKey) != 0);
- } else if (focus != nil) {
- keyCode = (SInt16)(curEvent.message & keyCodeMask);
- HandleControlKey (focus, keyCode, ch, (SInt16)curEvent.modifiers);
- mDoc->mEngine->SetDirty ();
- } else {
- SysBeep (1);
- }
- }
-
- //----------
- void TabPanel::Resize ()
- {
- /* application-specific code to resize items in window */
- }
-
- //----------
- void TabPanel::Scroll (
- short newValue,
- short oldValue)
- {
- /* application-specific code to scroll window */
- if (gWhichScroll == vScroll) {
- } else { // horizontal
- }
- }
-
- //----------
- void TabPanel::DoUndo ()
- {
- } // DoUndo
-
- //----------
- void TabPanel::DoCut ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TECut (curTE);
- mDoc->mEngine->SetDirty ();
- scrapDirty = true;
- }
- } // DoCut
-
- //----------
- void TabPanel::DoCopy ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TECopy (curTE);
- scrapDirty = true;
- }
- } // DoCopy
-
- //----------
- void TabPanel::DoPaste ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TEPaste (curTE);
- mDoc->mEngine->SetDirty ();
- }
- } // DoPaste
-
- //----------
- void TabPanel::DoClear ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TEDelete (curTE);
- mDoc->mEngine->SetDirty ();
- }
- } // DoClear
-
- //----------
- void TabPanel::DoSelectAll ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TESetSelect (0, 32767, curTE);
- }
- } // DoSelectAll
-
- //----------
- void TabPanel::DoShowClipboard ()
- {
- } // DoShowClipboard
-
- //----------
- Boolean TabPanel::DoCommand (
- long inCommand)
- {
- Boolean result = true;
-
- switch (inCommand) {
- case cmdUndo:
- DoUndo ();
- break;
- case cmdCut:
- DoCut ();
- break;
- case cmdCopy:
- DoCopy ();
- break;
- case cmdPaste:
- DoPaste ();
- break;
- case cmdClear:
- DoClear ();
- break;
- case cmdSelectAll:
- DoSelectAll ();
- break;
- case cmdShowClipboard:
- DoShowClipboard ();
- break;
-
- default:
- result = false;
- } // switch
-
- return result;
- }
-